package com.dlc.felear.xiaoensale.activity;

import android.text.TextUtils;
import android.widget.EditText;
import android.widget.GridView;

import com.dlc.felear.xiaoensale.R;
import com.dlc.felear.xiaoensale.adapter.TiaoLiaoSpeedAdapter;
import com.dlc.felear.xiaoensale.constant.Constant;
import com.dlc.felear.xiaoensale.dao.FlavourSpeedDao;
import com.dlc.felear.xiaoensale.deviceUtil.TopbarHelper;
import com.dlc.felear.xiaoensale.entity.FlavourSpeed;
import com.itdlc.android.library.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 调料参数设置页面
 */
public class FlavourParamerSettingActivity extends BaseActivity {
    private static final String TAG = "FlavourParamer";
    private TopbarHelper topbarHelper;
    private FlavourSpeedDao flavourSpeedDao;
    @BindView(R.id.fgv)
    GridView fgv;
    @BindView(R.id.fgv1)
    GridView fgv1;
    private TiaoLiaoSpeedAdapter adapter1;
    private TiaoLiaoSpeedAdapter adapter2;

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_flavour_paramer_setting;
    }

    @Override
    protected void initialView() {
        topbarHelper = new TopbarHelper(this);
        topbarHelper.setTitle("调料参数设置");
        topbarHelper.setcon(R.drawable.arrow_left);
        topbarHelper.setNavActivity(LoadDataActivity.class);
        flavourSpeedDao=new FlavourSpeedDao(this);
        initetData();
    }


    private void initetData() {
        adapter1=new TiaoLiaoSpeedAdapter(this,getData1(),2);
        adapter2=new TiaoLiaoSpeedAdapter(this,getData2(),1);
        fgv.setAdapter(adapter1);
        fgv1.setAdapter(adapter2);
    }

    private List<FlavourSpeed>  getData1(){
        List<FlavourSpeed> arr=new ArrayList<>();
        List<FlavourSpeed> temp2=flavourSpeedDao.queryForType(2);
        if(temp2!=null){
            for (FlavourSpeed flavourSpeed:temp2){
                if(TextUtils.equals(flavourSpeed.getName(), Constant.ACTION_NAME_JLA)){
                  continue;
                }
                arr.add(flavourSpeed);
            }
        }
        return arr;
    }
    private List<FlavourSpeed>  getData2(){
        List<FlavourSpeed> arr=new ArrayList<>();
        List<FlavourSpeed> temp2=flavourSpeedDao.queryForType(2);
        if(temp2!=null){
            for (FlavourSpeed flavourSpeed:temp2){
                arr.add(flavourSpeed);
            }
        }
        return arr;
    }

    private String etValue(EditText et) {
        return et.getText().toString();
    }

    private boolean checkEmpty() {

        return false;
    }

    private boolean checkZelo(EditText editText) {
        String temp = editText.getText().toString().trim();
        if (TextUtils.isEmpty(temp)) {
            return true;
        }
        try {
            if (Float.parseFloat(temp) <= 0) {
                return true;
            }
        } catch (Exception e) {
            return true;
        }

        return false;
    }

    private String getEtString(EditText et) {
        return et.getText().toString();
    }

}